{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f040009a-6283-42e4-9b5a-e105cc335740",
   "metadata": {},
   "source": [
    "import polars as pl "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 264,
   "id": "13687e74-3703-4841-860f-3f2edbf20138",
   "metadata": {},
   "outputs": [],
   "source": [
    "def read_df_湘财(f:str | Path )-> pl.DataFrame:\n",
    "    df=pl.read_csv(f, encoding=\"gb18030\",separator=\"\\t\",infer_schema=False)\n",
    "    df=df.with_columns(\n",
    "        pl.selectors.all().str.strip_prefix(\"=\").str.strip_chars('\"'),\n",
    "    ).with_columns(\n",
    "        pl.col(\"发生日期\").str.to_date(\"%Y%m%d\"),\n",
    "        pl.col(\"成交时间\").str.to_time(),\n",
    "        pl.col(\"成交数量\",\"成交价格\",\"成交金额\",\"发生金额\",\"手续费\",\"印花税\",\"过户费\",\"其他费\").cast(pl.Float64),\n",
    "    )\n",
    "    df[:,\"证券代码\"].unique().to_list()\n",
    "    df=df.filter(\n",
    "        pl.col(\"业务名称\").is_in([\"证券买入\", \"证券卖出\"]),\n",
    "    )\n",
    "    return df\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 265,
   "id": "512f4523-80a8-4924-9ff2-536f96a90234",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pathlib import Path\n",
    "\n",
    "# 你的其他代码\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 266,
   "id": "72fd928e-378a-451d-84ea-d968bde67132",
   "metadata": {},
   "outputs": [],
   "source": [
    "df=[read_df_湘财(f) for f in Path(\"stock_trades/\").glob(\"*-湘财.xls\")]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 267,
   "id": "810a861d-d477-4785-8c71-4f617e6ed82c",
   "metadata": {},
   "outputs": [],
   "source": [
    "d1=pl.concat(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 268,
   "id": "78f3ba85-883e-487d-aa02-3c361b851a47",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "d1=d1.with_columns(\n",
    "    券商=pl.lit(\"湘财\"),\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 269,
   "id": "1ffdc9c0-ebe1-4e3c-9b03-ddac7db0ee8c",
   "metadata": {},
   "outputs": [],
   "source": [
    "def read_df_海通普通(f:str | Path)->pl.DataFrame:\n",
    "    df=pl.read_excel(\n",
    "        f,\n",
    "        schema_overrides={\n",
    "            \"成交日期\":pl.String,\n",
    "            \"成交时间\":pl.String,\n",
    "            \"成交金额\":pl.Float64,\n",
    "            \"印花税\":pl.Float64,\n",
    "            \"其他费\":pl.Float64,\n",
    "            \"成交数量\":pl.Float64,\n",
    "        },\n",
    "    )\n",
    "    df=df.filter(pl.col(\"成交时间\")!=\"\").filter(\n",
    "            pl.col(\"操作\").is_in([\"买\",\"卖\"])\n",
    "        ).filter(\n",
    "            (~pl.col(\"证券代码\").str.starts_with(\"204\")) &\n",
    "            (~pl.col(\"证券代码\").str.starts_with(\"1318\"))\n",
    "        ).with_columns(\n",
    "            pl.col(\"成交日期\").str.to_date(\"%Y%m%d\"),\n",
    "            pl.col(\"成交时间\").str.to_time(\"%H:%M:%S\"),\n",
    "        )\n",
    "    return df\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 270,
   "id": "eb1321f2-98c7-49e3-9d6c-c51d6b7b11f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (53, 15)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>证券代码</th><th>证券名称</th><th>成交日期</th><th>成交时间</th><th>成交数量</th><th>成交价格</th><th>成交金额</th><th>发生金额</th><th>操作</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>备注</th><th>券商</th></tr><tr><td>str</td><td>str</td><td>date</td><td>time</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;600626&quot;</td><td>&quot;申达股份&quot;</td><td>2023-05-24</td><td>10:06:14</td><td>14800.0</td><td>3.37</td><td>49876.0</td><td>-49881.48</td><td>&quot;买&quot;</td><td>4.99</td><td>0.0</td><td>0.49</td><td>0.0</td><td>&quot;申达股份证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;600178&quot;</td><td>&quot;东安动力&quot;</td><td>2023-05-24</td><td>09:59:17</td><td>16400.0</td><td>6.07</td><td>99548.0</td><td>-99558.97</td><td>&quot;买&quot;</td><td>9.95</td><td>0.0</td><td>1.02</td><td>0.0</td><td>&quot;东安动力证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;603002&quot;</td><td>&quot;宏昌电子&quot;</td><td>2023-05-24</td><td>09:54:48</td><td>9800.0</td><td>5.06</td><td>49588.0</td><td>-49593.46</td><td>&quot;买&quot;</td><td>4.96</td><td>0.0</td><td>0.5</td><td>0.0</td><td>&quot;宏昌电子证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;300107&quot;</td><td>&quot;建新股份&quot;</td><td>2023-05-23</td><td>10:01:57</td><td>10000.0</td><td>5.0</td><td>50000.0</td><td>-50005.0</td><td>&quot;买&quot;</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;建新股份证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;002224&quot;</td><td>&quot;三 力 士&quot;</td><td>2023-05-23</td><td>09:58:07</td><td>10800.0</td><td>4.59</td><td>49572.0</td><td>-49576.96</td><td>&quot;买&quot;</td><td>4.96</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;三 力 士证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;605196&quot;</td><td>&quot;华通线缆&quot;</td><td>2023-07-17</td><td>10:03:09</td><td>7200.0</td><td>7.81</td><td>56232.0</td><td>56169.59</td><td>&quot;卖&quot;</td><td>5.62</td><td>56.23</td><td>0.56</td><td>0.0</td><td>&quot;华通线缆证券卖出&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;002842&quot;</td><td>&quot;翔鹭钨业&quot;</td><td>2023-07-11</td><td>10:04:39</td><td>5900.0</td><td>8.68</td><td>51212.0</td><td>51155.66</td><td>&quot;卖&quot;</td><td>5.12</td><td>51.22</td><td>0.0</td><td>0.0</td><td>&quot;翔鹭钨业证券卖出&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;002331&quot;</td><td>&quot;皖通科技&quot;</td><td>2023-07-11</td><td>10:03:52</td><td>6900.0</td><td>7.33</td><td>50577.0</td><td>50521.36</td><td>&quot;卖&quot;</td><td>5.06</td><td>50.58</td><td>0.0</td><td>0.0</td><td>&quot;皖通科技证券卖出&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;600300&quot;</td><td>&quot;维维股份&quot;</td><td>2023-07-11</td><td>10:13:04</td><td>16400.0</td><td>3.05</td><td>50020.0</td><td>-50025.5</td><td>&quot;买&quot;</td><td>5.0</td><td>0.0</td><td>0.5</td><td>0.0</td><td>&quot;维维股份证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;600287&quot;</td><td>&quot;江苏舜天&quot;</td><td>2023-07-11</td><td>10:08:50</td><td>9900.0</td><td>5.06</td><td>50094.0</td><td>-50099.51</td><td>&quot;买&quot;</td><td>5.01</td><td>0.0</td><td>0.5</td><td>0.0</td><td>&quot;江苏舜天证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (53, 15)\n",
       "┌──────────┬──────────┬────────────┬──────────┬───┬────────┬────────┬──────────────────┬──────────┐\n",
       "│ 证券代码 ┆ 证券名称 ┆ 成交日期   ┆ 成交时间 ┆ … ┆ 过户费 ┆ 其他费 ┆ 备注             ┆ 券商     │\n",
       "│ ---      ┆ ---      ┆ ---        ┆ ---      ┆   ┆ ---    ┆ ---    ┆ ---              ┆ ---      │\n",
       "│ str      ┆ str      ┆ date       ┆ time     ┆   ┆ f64    ┆ f64    ┆ str              ┆ str      │\n",
       "╞══════════╪══════════╪════════════╪══════════╪═══╪════════╪════════╪══════════════════╪══════════╡\n",
       "│ 600626   ┆ 申达股份 ┆ 2023-05-24 ┆ 10:06:14 ┆ … ┆ 0.49   ┆ 0.0    ┆ 申达股份证券买入 ┆ 海通普通 │\n",
       "│ 600178   ┆ 东安动力 ┆ 2023-05-24 ┆ 09:59:17 ┆ … ┆ 1.02   ┆ 0.0    ┆ 东安动力证券买入 ┆ 海通普通 │\n",
       "│ 603002   ┆ 宏昌电子 ┆ 2023-05-24 ┆ 09:54:48 ┆ … ┆ 0.5    ┆ 0.0    ┆ 宏昌电子证券买入 ┆ 海通普通 │\n",
       "│ 300107   ┆ 建新股份 ┆ 2023-05-23 ┆ 10:01:57 ┆ … ┆ 0.0    ┆ 0.0    ┆ 建新股份证券买入 ┆ 海通普通 │\n",
       "│ 002224   ┆ 三 力 士 ┆ 2023-05-23 ┆ 09:58:07 ┆ … ┆ 0.0    ┆ 0.0    ┆ 三 力 士证券买入 ┆ 海通普通 │\n",
       "│ …        ┆ …        ┆ …          ┆ …        ┆ … ┆ …      ┆ …      ┆ …                ┆ …        │\n",
       "│ 605196   ┆ 华通线缆 ┆ 2023-07-17 ┆ 10:03:09 ┆ … ┆ 0.56   ┆ 0.0    ┆ 华通线缆证券卖出 ┆ 海通普通 │\n",
       "│ 002842   ┆ 翔鹭钨业 ┆ 2023-07-11 ┆ 10:04:39 ┆ … ┆ 0.0    ┆ 0.0    ┆ 翔鹭钨业证券卖出 ┆ 海通普通 │\n",
       "│ 002331   ┆ 皖通科技 ┆ 2023-07-11 ┆ 10:03:52 ┆ … ┆ 0.0    ┆ 0.0    ┆ 皖通科技证券卖出 ┆ 海通普通 │\n",
       "│ 600300   ┆ 维维股份 ┆ 2023-07-11 ┆ 10:13:04 ┆ … ┆ 0.5    ┆ 0.0    ┆ 维维股份证券买入 ┆ 海通普通 │\n",
       "│ 600287   ┆ 江苏舜天 ┆ 2023-07-11 ┆ 10:08:50 ┆ … ┆ 0.5    ┆ 0.0    ┆ 江苏舜天证券买入 ┆ 海通普通 │\n",
       "└──────────┴──────────┴────────────┴──────────┴───┴────────┴────────┴──────────────────┴──────────┘"
      ]
     },
     "execution_count": 270,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df=[read_df_海通普通(p) for p in Path(\"stock_trades/\").glob(\"*-海通普通.xlsx\")] \n",
    "df = pl.concat(df)\n",
    "d2=df.with_columns(\n",
    "    券商=pl.lit(\"海通普通\"),\n",
    ")\n",
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 271,
   "id": "2fa496c7-2df1-4dbb-8dc6-b95502613143",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (53, 15)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>证券代码</th><th>证券名称</th><th>成交日期</th><th>成交时间</th><th>成交数量</th><th>成交价格</th><th>成交金额</th><th>发生金额</th><th>操作</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>备注</th><th>券商</th></tr><tr><td>str</td><td>str</td><td>date</td><td>time</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;600638&quot;</td><td>&quot;新黄浦&quot;</td><td>2023-07-26</td><td>09:33:56</td><td>9300.0</td><td>6.526</td><td>60696.0</td><td>60628.01</td><td>&quot;卖&quot;</td><td>6.68</td><td>60.7</td><td>0.61</td><td>0.0</td><td>&quot;新黄浦证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;002492&quot;</td><td>&quot;恒基达鑫&quot;</td><td>2023-07-27</td><td>09:30:42</td><td>8700.0</td><td>6.12</td><td>53244.0</td><td>53184.91</td><td>&quot;卖&quot;</td><td>5.86</td><td>53.23</td><td>0.0</td><td>0.0</td><td>&quot;恒基达鑫证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;002136&quot;</td><td>&quot;安 纳 达&quot;</td><td>2023-07-27</td><td>09:32:52</td><td>4400.0</td><td>11.881</td><td>52277.0</td><td>52218.97</td><td>&quot;卖&quot;</td><td>5.75</td><td>52.28</td><td>0.0</td><td>0.0</td><td>&quot;安 纳 达证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;603967&quot;</td><td>&quot;中创物流&quot;</td><td>2023-08-22</td><td>09:36:13</td><td>10600.0</td><td>9.36</td><td>99216.0</td><td>99104.85</td><td>&quot;卖&quot;</td><td>10.91</td><td>99.24</td><td>1.0</td><td>0.0</td><td>&quot;中创物流证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;603967&quot;</td><td>&quot;中创物流&quot;</td><td>2023-08-04</td><td>10:07:37</td><td>10600.0</td><td>9.43</td><td>99958.0</td><td>-99970.01</td><td>&quot;买&quot;</td><td>11.0</td><td>0.0</td><td>1.01</td><td>0.0</td><td>&quot;中创物流证券买入&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;300464&quot;</td><td>&quot;星徽股份&quot;</td><td>2023-10-18</td><td>09:46:15</td><td>16100.0</td><td>5.74</td><td>92414.0</td><td>92358.97</td><td>&quot;卖&quot;</td><td>8.82</td><td>46.21</td><td>0.0</td><td>0.0</td><td>&quot;星徽股份证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;002661&quot;</td><td>&quot;克明食品&quot;</td><td>2023-10-18</td><td>09:55:41</td><td>8500.0</td><td>9.42</td><td>80072.0</td><td>-80079.64</td><td>&quot;买&quot;</td><td>7.64</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;克明食品证券买入&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;002753&quot;</td><td>&quot;永东股份&quot;</td><td>2023-10-09</td><td>09:48:02</td><td>14200.0</td><td>7.02</td><td>99684.0</td><td>-99693.51</td><td>&quot;买&quot;</td><td>9.51</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;永东股份证券买入&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;000698&quot;</td><td>&quot;沈阳化工&quot;</td><td>2023-10-09</td><td>09:45:18</td><td>23800.0</td><td>4.053</td><td>96460.0</td><td>96402.56</td><td>&quot;卖&quot;</td><td>9.2</td><td>48.24</td><td>0.0</td><td>0.0</td><td>&quot;沈阳化工证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;605288&quot;</td><td>&quot;凯迪股份&quot;</td><td>2023-10-09</td><td>09:44:40</td><td>2500.0</td><td>40.838</td><td>102094.0</td><td>102032.21</td><td>&quot;卖&quot;</td><td>9.74</td><td>51.05</td><td>1.0</td><td>0.0</td><td>&quot;凯迪股份证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (53, 15)\n",
       "┌──────────┬──────────┬────────────┬──────────┬───┬────────┬────────┬──────────────────┬──────────┐\n",
       "│ 证券代码 ┆ 证券名称 ┆ 成交日期   ┆ 成交时间 ┆ … ┆ 过户费 ┆ 其他费 ┆ 备注             ┆ 券商     │\n",
       "│ ---      ┆ ---      ┆ ---        ┆ ---      ┆   ┆ ---    ┆ ---    ┆ ---              ┆ ---      │\n",
       "│ str      ┆ str      ┆ date       ┆ time     ┆   ┆ f64    ┆ f64    ┆ str              ┆ str      │\n",
       "╞══════════╪══════════╪════════════╪══════════╪═══╪════════╪════════╪══════════════════╪══════════╡\n",
       "│ 600638   ┆ 新黄浦   ┆ 2023-07-26 ┆ 09:33:56 ┆ … ┆ 0.61   ┆ 0.0    ┆ 新黄浦证券卖出   ┆ 海通两融 │\n",
       "│ 002492   ┆ 恒基达鑫 ┆ 2023-07-27 ┆ 09:30:42 ┆ … ┆ 0.0    ┆ 0.0    ┆ 恒基达鑫证券卖出 ┆ 海通两融 │\n",
       "│ 002136   ┆ 安 纳 达 ┆ 2023-07-27 ┆ 09:32:52 ┆ … ┆ 0.0    ┆ 0.0    ┆ 安 纳 达证券卖出 ┆ 海通两融 │\n",
       "│ 603967   ┆ 中创物流 ┆ 2023-08-22 ┆ 09:36:13 ┆ … ┆ 1.0    ┆ 0.0    ┆ 中创物流证券卖出 ┆ 海通两融 │\n",
       "│ 603967   ┆ 中创物流 ┆ 2023-08-04 ┆ 10:07:37 ┆ … ┆ 1.01   ┆ 0.0    ┆ 中创物流证券买入 ┆ 海通两融 │\n",
       "│ …        ┆ …        ┆ …          ┆ …        ┆ … ┆ …      ┆ …      ┆ …                ┆ …        │\n",
       "│ 300464   ┆ 星徽股份 ┆ 2023-10-18 ┆ 09:46:15 ┆ … ┆ 0.0    ┆ 0.0    ┆ 星徽股份证券卖出 ┆ 海通两融 │\n",
       "│ 002661   ┆ 克明食品 ┆ 2023-10-18 ┆ 09:55:41 ┆ … ┆ 0.0    ┆ 0.0    ┆ 克明食品证券买入 ┆ 海通两融 │\n",
       "│ 002753   ┆ 永东股份 ┆ 2023-10-09 ┆ 09:48:02 ┆ … ┆ 0.0    ┆ 0.0    ┆ 永东股份证券买入 ┆ 海通两融 │\n",
       "│ 000698   ┆ 沈阳化工 ┆ 2023-10-09 ┆ 09:45:18 ┆ … ┆ 0.0    ┆ 0.0    ┆ 沈阳化工证券卖出 ┆ 海通两融 │\n",
       "│ 605288   ┆ 凯迪股份 ┆ 2023-10-09 ┆ 09:44:40 ┆ … ┆ 1.0    ┆ 0.0    ┆ 凯迪股份证券卖出 ┆ 海通两融 │\n",
       "└──────────┴──────────┴────────────┴──────────┴───┴────────┴────────┴──────────────────┴──────────┘"
      ]
     },
     "execution_count": 271,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df=[read_df_海通普通(p) for p in Path(\"stock_trades/\").glob(\"*-海通两融.xlsx\")] \n",
    "df = pl.concat(df)\n",
    "d3=df.with_columns(\n",
    "    券商=pl.lit(\"海通两融\"),\n",
    ")\n",
    "d3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 272,
   "id": "3ed40bd1-09e8-4fba-892e-5b15c38369dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (257, 17)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>发生日期</th><th>证券代码</th><th>证券名称</th><th>买卖标志</th><th>业务名称</th><th>成交时间</th><th>成交数量</th><th>成交价格</th><th>成交金额</th><th>发生金额</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>备注</th><th>币种</th><th>券商</th></tr><tr><td>date</td><td>str</td><td>str</td><td>str</td><td>str</td><td>time</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>2022-07-18</td><td>&quot;002462&quot;</td><td>&quot;嘉事堂&quot;</td><td>&quot;卖出&quot;</td><td>&quot;证券卖出&quot;</td><td>09:38:10</td><td>-10400.0</td><td>13.2062</td><td>137344.0</td><td>137184.67</td><td>21.98</td><td>137.35</td><td>1.38</td><td>0.0</td><td>&quot;证券卖出&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2022-07-18</td><td>&quot;600408&quot;</td><td>&quot;安泰集团&quot;</td><td>&quot;买入&quot;</td><td>&quot;证券买入&quot;</td><td>09:44:52</td><td>47000.0</td><td>3.19</td><td>149930.0</td><td>-149955.5</td><td>23.99</td><td>0.0</td><td>1.51</td><td>0.0</td><td>&quot;证券买入&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2022-07-18</td><td>&quot;600648&quot;</td><td>&quot;外高桥&quot;</td><td>&quot;买入&quot;</td><td>&quot;证券买入&quot;</td><td>09:44:31</td><td>11900.0</td><td>12.6066</td><td>150019.0</td><td>-150044.49</td><td>24.0</td><td>0.0</td><td>1.49</td><td>0.0</td><td>&quot;证券买入&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2022-07-18</td><td>&quot;600269&quot;</td><td>&quot;赣粤高速&quot;</td><td>&quot;买入&quot;</td><td>&quot;证券买入&quot;</td><td>09:43:38</td><td>40700.0</td><td>3.69</td><td>150183.0</td><td>-150208.53</td><td>24.03</td><td>0.0</td><td>1.5</td><td>0.0</td><td>&quot;证券买入&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2022-07-18</td><td>&quot;600015&quot;</td><td>&quot;华夏银行&quot;</td><td>&quot;买入&quot;</td><td>&quot;证券买入&quot;</td><td>09:42:51</td><td>30000.0</td><td>5.07</td><td>152100.0</td><td>-152125.86</td><td>24.34</td><td>0.0</td><td>1.52</td><td>0.0</td><td>&quot;证券买入&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>2023-06-19</td><td>&quot;603967&quot;</td><td>&quot;中创物流&quot;</td><td>&quot;卖出&quot;</td><td>&quot;证券卖出&quot;</td><td>10:18:46</td><td>-5000.0</td><td>9.13</td><td>45650.0</td><td>45596.59</td><td>7.3</td><td>45.65</td><td>0.46</td><td>0.0</td><td>&quot;证券卖出&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2023-06-12</td><td>&quot;300641&quot;</td><td>&quot;正丹股份&quot;</td><td>&quot;卖出&quot;</td><td>&quot;证券卖出&quot;</td><td>13:22:32</td><td>-9600.0</td><td>5.05</td><td>48480.0</td><td>48423.76</td><td>7.76</td><td>48.48</td><td>0.48</td><td>0.0</td><td>&quot;证券卖出&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2023-06-02</td><td>&quot;000655&quot;</td><td>&quot;金岭矿业&quot;</td><td>&quot;卖出&quot;</td><td>&quot;证券卖出&quot;</td><td>10:26:35</td><td>-7500.0</td><td>6.48</td><td>48600.0</td><td>48543.61</td><td>7.78</td><td>48.61</td><td>0.47</td><td>0.0</td><td>&quot;证券卖出&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2023-06-01</td><td>&quot;300214&quot;</td><td>&quot;日科化学&quot;</td><td>&quot;卖出&quot;</td><td>&quot;证券卖出&quot;</td><td>10:45:35</td><td>-7400.0</td><td>6.8</td><td>50320.0</td><td>50261.63</td><td>8.05</td><td>50.32</td><td>0.51</td><td>0.0</td><td>&quot;证券卖出&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr><tr><td>2023-09-11</td><td>&quot;603577&quot;</td><td>&quot;汇金通&quot;</td><td>&quot;卖出&quot;</td><td>&quot;证券卖出&quot;</td><td>09:46:10</td><td>-5100.0</td><td>9.3024</td><td>47442.0</td><td>47410.89</td><td>6.9</td><td>23.72</td><td>0.49</td><td>0.0</td><td>&quot;证券卖出&quot;</td><td>&quot;人民币&quot;</td><td>&quot;湘财&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (257, 17)\n",
       "┌────────────┬──────────┬──────────┬──────────┬───┬────────┬──────────┬────────┬──────┐\n",
       "│ 发生日期   ┆ 证券代码 ┆ 证券名称 ┆ 买卖标志 ┆ … ┆ 其他费 ┆ 备注     ┆ 币种   ┆ 券商 │\n",
       "│ ---        ┆ ---      ┆ ---      ┆ ---      ┆   ┆ ---    ┆ ---      ┆ ---    ┆ ---  │\n",
       "│ date       ┆ str      ┆ str      ┆ str      ┆   ┆ f64    ┆ str      ┆ str    ┆ str  │\n",
       "╞════════════╪══════════╪══════════╪══════════╪═══╪════════╪══════════╪════════╪══════╡\n",
       "│ 2022-07-18 ┆ 002462   ┆ 嘉事堂   ┆ 卖出     ┆ … ┆ 0.0    ┆ 证券卖出 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2022-07-18 ┆ 600408   ┆ 安泰集团 ┆ 买入     ┆ … ┆ 0.0    ┆ 证券买入 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2022-07-18 ┆ 600648   ┆ 外高桥   ┆ 买入     ┆ … ┆ 0.0    ┆ 证券买入 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2022-07-18 ┆ 600269   ┆ 赣粤高速 ┆ 买入     ┆ … ┆ 0.0    ┆ 证券买入 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2022-07-18 ┆ 600015   ┆ 华夏银行 ┆ 买入     ┆ … ┆ 0.0    ┆ 证券买入 ┆ 人民币 ┆ 湘财 │\n",
       "│ …          ┆ …        ┆ …        ┆ …        ┆ … ┆ …      ┆ …        ┆ …      ┆ …    │\n",
       "│ 2023-06-19 ┆ 603967   ┆ 中创物流 ┆ 卖出     ┆ … ┆ 0.0    ┆ 证券卖出 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2023-06-12 ┆ 300641   ┆ 正丹股份 ┆ 卖出     ┆ … ┆ 0.0    ┆ 证券卖出 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2023-06-02 ┆ 000655   ┆ 金岭矿业 ┆ 卖出     ┆ … ┆ 0.0    ┆ 证券卖出 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2023-06-01 ┆ 300214   ┆ 日科化学 ┆ 卖出     ┆ … ┆ 0.0    ┆ 证券卖出 ┆ 人民币 ┆ 湘财 │\n",
       "│ 2023-09-11 ┆ 603577   ┆ 汇金通   ┆ 卖出     ┆ … ┆ 0.0    ┆ 证券卖出 ┆ 人民币 ┆ 湘财 │\n",
       "└────────────┴──────────┴──────────┴──────────┴───┴────────┴──────────┴────────┴──────┘"
      ]
     },
     "execution_count": 272,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 273,
   "id": "f65a257d-a5c6-409e-ba25-62adc8cdf64d",
   "metadata": {},
   "outputs": [],
   "source": [
    "d1=d1.select(\n",
    "    券商=pl.col(\"券商\"),\n",
    "    交易日期=pl.col(\"发生日期\"),\n",
    "    交易时间=pl.col(\"成交时间\"),\n",
    "    证券代码=pl.col(\"证券代码\"),\n",
    "    证券名称=pl.col(\"证券名称\"),\n",
    "    买卖标志=pl.col(\"业务名称\").replace({\"证券卖出\":\"卖出\",\"证券买入\":\"买入\"}),\n",
    "    成交价格=pl.col(\"成交价格\"),\n",
    "    成交数量=pl.col(\"成交数量\").abs(),\n",
    "    成交金额=pl.col(\"成交金额\"),\n",
    "    手续费=pl.col(\"手续费\"),\n",
    "    印花税=pl.col(\"印花税\"),\n",
    "    过户费=pl.col(\"过户费\"),\n",
    "    其他费=pl.col(\"其他费\"),\n",
    "    发生金额=pl.col(\"发生金额\"),\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 274,
   "id": "7d7255cb-2dd4-4598-83ab-6d07f140c4d5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (53, 15)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>证券代码</th><th>证券名称</th><th>成交日期</th><th>成交时间</th><th>成交数量</th><th>成交价格</th><th>成交金额</th><th>发生金额</th><th>操作</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>备注</th><th>券商</th></tr><tr><td>str</td><td>str</td><td>date</td><td>time</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;600626&quot;</td><td>&quot;申达股份&quot;</td><td>2023-05-24</td><td>10:06:14</td><td>14800.0</td><td>3.37</td><td>49876.0</td><td>-49881.48</td><td>&quot;买&quot;</td><td>4.99</td><td>0.0</td><td>0.49</td><td>0.0</td><td>&quot;申达股份证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;600178&quot;</td><td>&quot;东安动力&quot;</td><td>2023-05-24</td><td>09:59:17</td><td>16400.0</td><td>6.07</td><td>99548.0</td><td>-99558.97</td><td>&quot;买&quot;</td><td>9.95</td><td>0.0</td><td>1.02</td><td>0.0</td><td>&quot;东安动力证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;603002&quot;</td><td>&quot;宏昌电子&quot;</td><td>2023-05-24</td><td>09:54:48</td><td>9800.0</td><td>5.06</td><td>49588.0</td><td>-49593.46</td><td>&quot;买&quot;</td><td>4.96</td><td>0.0</td><td>0.5</td><td>0.0</td><td>&quot;宏昌电子证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;300107&quot;</td><td>&quot;建新股份&quot;</td><td>2023-05-23</td><td>10:01:57</td><td>10000.0</td><td>5.0</td><td>50000.0</td><td>-50005.0</td><td>&quot;买&quot;</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;建新股份证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;002224&quot;</td><td>&quot;三 力 士&quot;</td><td>2023-05-23</td><td>09:58:07</td><td>10800.0</td><td>4.59</td><td>49572.0</td><td>-49576.96</td><td>&quot;买&quot;</td><td>4.96</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;三 力 士证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;605196&quot;</td><td>&quot;华通线缆&quot;</td><td>2023-07-17</td><td>10:03:09</td><td>7200.0</td><td>7.81</td><td>56232.0</td><td>56169.59</td><td>&quot;卖&quot;</td><td>5.62</td><td>56.23</td><td>0.56</td><td>0.0</td><td>&quot;华通线缆证券卖出&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;002842&quot;</td><td>&quot;翔鹭钨业&quot;</td><td>2023-07-11</td><td>10:04:39</td><td>5900.0</td><td>8.68</td><td>51212.0</td><td>51155.66</td><td>&quot;卖&quot;</td><td>5.12</td><td>51.22</td><td>0.0</td><td>0.0</td><td>&quot;翔鹭钨业证券卖出&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;002331&quot;</td><td>&quot;皖通科技&quot;</td><td>2023-07-11</td><td>10:03:52</td><td>6900.0</td><td>7.33</td><td>50577.0</td><td>50521.36</td><td>&quot;卖&quot;</td><td>5.06</td><td>50.58</td><td>0.0</td><td>0.0</td><td>&quot;皖通科技证券卖出&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;600300&quot;</td><td>&quot;维维股份&quot;</td><td>2023-07-11</td><td>10:13:04</td><td>16400.0</td><td>3.05</td><td>50020.0</td><td>-50025.5</td><td>&quot;买&quot;</td><td>5.0</td><td>0.0</td><td>0.5</td><td>0.0</td><td>&quot;维维股份证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr><tr><td>&quot;600287&quot;</td><td>&quot;江苏舜天&quot;</td><td>2023-07-11</td><td>10:08:50</td><td>9900.0</td><td>5.06</td><td>50094.0</td><td>-50099.51</td><td>&quot;买&quot;</td><td>5.01</td><td>0.0</td><td>0.5</td><td>0.0</td><td>&quot;江苏舜天证券买入&quot;</td><td>&quot;海通普通&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (53, 15)\n",
       "┌──────────┬──────────┬────────────┬──────────┬───┬────────┬────────┬──────────────────┬──────────┐\n",
       "│ 证券代码 ┆ 证券名称 ┆ 成交日期   ┆ 成交时间 ┆ … ┆ 过户费 ┆ 其他费 ┆ 备注             ┆ 券商     │\n",
       "│ ---      ┆ ---      ┆ ---        ┆ ---      ┆   ┆ ---    ┆ ---    ┆ ---              ┆ ---      │\n",
       "│ str      ┆ str      ┆ date       ┆ time     ┆   ┆ f64    ┆ f64    ┆ str              ┆ str      │\n",
       "╞══════════╪══════════╪════════════╪══════════╪═══╪════════╪════════╪══════════════════╪══════════╡\n",
       "│ 600626   ┆ 申达股份 ┆ 2023-05-24 ┆ 10:06:14 ┆ … ┆ 0.49   ┆ 0.0    ┆ 申达股份证券买入 ┆ 海通普通 │\n",
       "│ 600178   ┆ 东安动力 ┆ 2023-05-24 ┆ 09:59:17 ┆ … ┆ 1.02   ┆ 0.0    ┆ 东安动力证券买入 ┆ 海通普通 │\n",
       "│ 603002   ┆ 宏昌电子 ┆ 2023-05-24 ┆ 09:54:48 ┆ … ┆ 0.5    ┆ 0.0    ┆ 宏昌电子证券买入 ┆ 海通普通 │\n",
       "│ 300107   ┆ 建新股份 ┆ 2023-05-23 ┆ 10:01:57 ┆ … ┆ 0.0    ┆ 0.0    ┆ 建新股份证券买入 ┆ 海通普通 │\n",
       "│ 002224   ┆ 三 力 士 ┆ 2023-05-23 ┆ 09:58:07 ┆ … ┆ 0.0    ┆ 0.0    ┆ 三 力 士证券买入 ┆ 海通普通 │\n",
       "│ …        ┆ …        ┆ …          ┆ …        ┆ … ┆ …      ┆ …      ┆ …                ┆ …        │\n",
       "│ 605196   ┆ 华通线缆 ┆ 2023-07-17 ┆ 10:03:09 ┆ … ┆ 0.56   ┆ 0.0    ┆ 华通线缆证券卖出 ┆ 海通普通 │\n",
       "│ 002842   ┆ 翔鹭钨业 ┆ 2023-07-11 ┆ 10:04:39 ┆ … ┆ 0.0    ┆ 0.0    ┆ 翔鹭钨业证券卖出 ┆ 海通普通 │\n",
       "│ 002331   ┆ 皖通科技 ┆ 2023-07-11 ┆ 10:03:52 ┆ … ┆ 0.0    ┆ 0.0    ┆ 皖通科技证券卖出 ┆ 海通普通 │\n",
       "│ 600300   ┆ 维维股份 ┆ 2023-07-11 ┆ 10:13:04 ┆ … ┆ 0.5    ┆ 0.0    ┆ 维维股份证券买入 ┆ 海通普通 │\n",
       "│ 600287   ┆ 江苏舜天 ┆ 2023-07-11 ┆ 10:08:50 ┆ … ┆ 0.5    ┆ 0.0    ┆ 江苏舜天证券买入 ┆ 海通普通 │\n",
       "└──────────┴──────────┴────────────┴──────────┴───┴────────┴────────┴──────────────────┴──────────┘"
      ]
     },
     "execution_count": 274,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 275,
   "id": "e69b181d-74bd-41c9-b0ca-38899610b72c",
   "metadata": {},
   "outputs": [],
   "source": [
    "d2=d2.select(\n",
    "    券商=pl.col(\"券商\"),\n",
    "    交易日期=pl.col(\"成交日期\"),\n",
    "    交易时间=pl.col(\"成交时间\"),\n",
    "    证券代码=pl.col(\"证券代码\"),\n",
    "    证券名称=pl.col(\"证券名称\"),\n",
    "    买卖标志=pl.col(\"操作\").replace({\"卖\":\"卖出\",\"买\":\"买入\"}),\n",
    "    成交价格=pl.col(\"成交价格\"),\n",
    "    成交数量=pl.col(\"成交数量\").abs(),\n",
    "    成交金额=pl.col(\"成交金额\"),\n",
    "    手续费=pl.col(\"手续费\"),\n",
    "    印花税=pl.col(\"印花税\"),\n",
    "    过户费=pl.col(\"过户费\"),\n",
    "    其他费=pl.col(\"其他费\"),\n",
    "    发生金额=pl.col(\"发生金额\"),\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 276,
   "id": "9c1e7cd0-8599-49a0-90d2-1a6e00af2f12",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (53, 14)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>券商</th><th>交易日期</th><th>交易时间</th><th>证券代码</th><th>证券名称</th><th>买卖标志</th><th>成交价格</th><th>成交数量</th><th>成交金额</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>发生金额</th></tr><tr><td>str</td><td>date</td><td>time</td><td>str</td><td>str</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;海通普通&quot;</td><td>2023-05-24</td><td>10:06:14</td><td>&quot;600626&quot;</td><td>&quot;申达股份&quot;</td><td>&quot;买入&quot;</td><td>3.37</td><td>14800.0</td><td>49876.0</td><td>4.99</td><td>0.0</td><td>0.49</td><td>0.0</td><td>-49881.48</td></tr><tr><td>&quot;海通普通&quot;</td><td>2023-05-24</td><td>09:59:17</td><td>&quot;600178&quot;</td><td>&quot;东安动力&quot;</td><td>&quot;买入&quot;</td><td>6.07</td><td>16400.0</td><td>99548.0</td><td>9.95</td><td>0.0</td><td>1.02</td><td>0.0</td><td>-99558.97</td></tr><tr><td>&quot;海通普通&quot;</td><td>2023-05-24</td><td>09:54:48</td><td>&quot;603002&quot;</td><td>&quot;宏昌电子&quot;</td><td>&quot;买入&quot;</td><td>5.06</td><td>9800.0</td><td>49588.0</td><td>4.96</td><td>0.0</td><td>0.5</td><td>0.0</td><td>-49593.46</td></tr><tr><td>&quot;海通普通&quot;</td><td>2023-05-23</td><td>10:01:57</td><td>&quot;300107&quot;</td><td>&quot;建新股份&quot;</td><td>&quot;买入&quot;</td><td>5.0</td><td>10000.0</td><td>50000.0</td><td>5.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-50005.0</td></tr><tr><td>&quot;海通普通&quot;</td><td>2023-05-23</td><td>09:58:07</td><td>&quot;002224&quot;</td><td>&quot;三 力 士&quot;</td><td>&quot;买入&quot;</td><td>4.59</td><td>10800.0</td><td>49572.0</td><td>4.96</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-49576.96</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;海通普通&quot;</td><td>2023-07-17</td><td>10:03:09</td><td>&quot;605196&quot;</td><td>&quot;华通线缆&quot;</td><td>&quot;卖出&quot;</td><td>7.81</td><td>7200.0</td><td>56232.0</td><td>5.62</td><td>56.23</td><td>0.56</td><td>0.0</td><td>56169.59</td></tr><tr><td>&quot;海通普通&quot;</td><td>2023-07-11</td><td>10:04:39</td><td>&quot;002842&quot;</td><td>&quot;翔鹭钨业&quot;</td><td>&quot;卖出&quot;</td><td>8.68</td><td>5900.0</td><td>51212.0</td><td>5.12</td><td>51.22</td><td>0.0</td><td>0.0</td><td>51155.66</td></tr><tr><td>&quot;海通普通&quot;</td><td>2023-07-11</td><td>10:03:52</td><td>&quot;002331&quot;</td><td>&quot;皖通科技&quot;</td><td>&quot;卖出&quot;</td><td>7.33</td><td>6900.0</td><td>50577.0</td><td>5.06</td><td>50.58</td><td>0.0</td><td>0.0</td><td>50521.36</td></tr><tr><td>&quot;海通普通&quot;</td><td>2023-07-11</td><td>10:13:04</td><td>&quot;600300&quot;</td><td>&quot;维维股份&quot;</td><td>&quot;买入&quot;</td><td>3.05</td><td>16400.0</td><td>50020.0</td><td>5.0</td><td>0.0</td><td>0.5</td><td>0.0</td><td>-50025.5</td></tr><tr><td>&quot;海通普通&quot;</td><td>2023-07-11</td><td>10:08:50</td><td>&quot;600287&quot;</td><td>&quot;江苏舜天&quot;</td><td>&quot;买入&quot;</td><td>5.06</td><td>9900.0</td><td>50094.0</td><td>5.01</td><td>0.0</td><td>0.5</td><td>0.0</td><td>-50099.51</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (53, 14)\n",
       "┌──────────┬────────────┬──────────┬──────────┬───┬────────┬────────┬────────┬───────────┐\n",
       "│ 券商     ┆ 交易日期   ┆ 交易时间 ┆ 证券代码 ┆ … ┆ 印花税 ┆ 过户费 ┆ 其他费 ┆ 发生金额  │\n",
       "│ ---      ┆ ---        ┆ ---      ┆ ---      ┆   ┆ ---    ┆ ---    ┆ ---    ┆ ---       │\n",
       "│ str      ┆ date       ┆ time     ┆ str      ┆   ┆ f64    ┆ f64    ┆ f64    ┆ f64       │\n",
       "╞══════════╪════════════╪══════════╪══════════╪═══╪════════╪════════╪════════╪═══════════╡\n",
       "│ 海通普通 ┆ 2023-05-24 ┆ 10:06:14 ┆ 600626   ┆ … ┆ 0.0    ┆ 0.49   ┆ 0.0    ┆ -49881.48 │\n",
       "│ 海通普通 ┆ 2023-05-24 ┆ 09:59:17 ┆ 600178   ┆ … ┆ 0.0    ┆ 1.02   ┆ 0.0    ┆ -99558.97 │\n",
       "│ 海通普通 ┆ 2023-05-24 ┆ 09:54:48 ┆ 603002   ┆ … ┆ 0.0    ┆ 0.5    ┆ 0.0    ┆ -49593.46 │\n",
       "│ 海通普通 ┆ 2023-05-23 ┆ 10:01:57 ┆ 300107   ┆ … ┆ 0.0    ┆ 0.0    ┆ 0.0    ┆ -50005.0  │\n",
       "│ 海通普通 ┆ 2023-05-23 ┆ 09:58:07 ┆ 002224   ┆ … ┆ 0.0    ┆ 0.0    ┆ 0.0    ┆ -49576.96 │\n",
       "│ …        ┆ …          ┆ …        ┆ …        ┆ … ┆ …      ┆ …      ┆ …      ┆ …         │\n",
       "│ 海通普通 ┆ 2023-07-17 ┆ 10:03:09 ┆ 605196   ┆ … ┆ 56.23  ┆ 0.56   ┆ 0.0    ┆ 56169.59  │\n",
       "│ 海通普通 ┆ 2023-07-11 ┆ 10:04:39 ┆ 002842   ┆ … ┆ 51.22  ┆ 0.0    ┆ 0.0    ┆ 51155.66  │\n",
       "│ 海通普通 ┆ 2023-07-11 ┆ 10:03:52 ┆ 002331   ┆ … ┆ 50.58  ┆ 0.0    ┆ 0.0    ┆ 50521.36  │\n",
       "│ 海通普通 ┆ 2023-07-11 ┆ 10:13:04 ┆ 600300   ┆ … ┆ 0.0    ┆ 0.5    ┆ 0.0    ┆ -50025.5  │\n",
       "│ 海通普通 ┆ 2023-07-11 ┆ 10:08:50 ┆ 600287   ┆ … ┆ 0.0    ┆ 0.5    ┆ 0.0    ┆ -50099.51 │\n",
       "└──────────┴────────────┴──────────┴──────────┴───┴────────┴────────┴────────┴───────────┘"
      ]
     },
     "execution_count": 276,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 277,
   "id": "3a4dce57-a2c6-4303-98d3-6d667c5113cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (53, 15)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>证券代码</th><th>证券名称</th><th>成交日期</th><th>成交时间</th><th>成交数量</th><th>成交价格</th><th>成交金额</th><th>发生金额</th><th>操作</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>备注</th><th>券商</th></tr><tr><td>str</td><td>str</td><td>date</td><td>time</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>&quot;600638&quot;</td><td>&quot;新黄浦&quot;</td><td>2023-07-26</td><td>09:33:56</td><td>9300.0</td><td>6.526</td><td>60696.0</td><td>60628.01</td><td>&quot;卖&quot;</td><td>6.68</td><td>60.7</td><td>0.61</td><td>0.0</td><td>&quot;新黄浦证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;002492&quot;</td><td>&quot;恒基达鑫&quot;</td><td>2023-07-27</td><td>09:30:42</td><td>8700.0</td><td>6.12</td><td>53244.0</td><td>53184.91</td><td>&quot;卖&quot;</td><td>5.86</td><td>53.23</td><td>0.0</td><td>0.0</td><td>&quot;恒基达鑫证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;002136&quot;</td><td>&quot;安 纳 达&quot;</td><td>2023-07-27</td><td>09:32:52</td><td>4400.0</td><td>11.881</td><td>52277.0</td><td>52218.97</td><td>&quot;卖&quot;</td><td>5.75</td><td>52.28</td><td>0.0</td><td>0.0</td><td>&quot;安 纳 达证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;603967&quot;</td><td>&quot;中创物流&quot;</td><td>2023-08-22</td><td>09:36:13</td><td>10600.0</td><td>9.36</td><td>99216.0</td><td>99104.85</td><td>&quot;卖&quot;</td><td>10.91</td><td>99.24</td><td>1.0</td><td>0.0</td><td>&quot;中创物流证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;603967&quot;</td><td>&quot;中创物流&quot;</td><td>2023-08-04</td><td>10:07:37</td><td>10600.0</td><td>9.43</td><td>99958.0</td><td>-99970.01</td><td>&quot;买&quot;</td><td>11.0</td><td>0.0</td><td>1.01</td><td>0.0</td><td>&quot;中创物流证券买入&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;300464&quot;</td><td>&quot;星徽股份&quot;</td><td>2023-10-18</td><td>09:46:15</td><td>16100.0</td><td>5.74</td><td>92414.0</td><td>92358.97</td><td>&quot;卖&quot;</td><td>8.82</td><td>46.21</td><td>0.0</td><td>0.0</td><td>&quot;星徽股份证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;002661&quot;</td><td>&quot;克明食品&quot;</td><td>2023-10-18</td><td>09:55:41</td><td>8500.0</td><td>9.42</td><td>80072.0</td><td>-80079.64</td><td>&quot;买&quot;</td><td>7.64</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;克明食品证券买入&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;002753&quot;</td><td>&quot;永东股份&quot;</td><td>2023-10-09</td><td>09:48:02</td><td>14200.0</td><td>7.02</td><td>99684.0</td><td>-99693.51</td><td>&quot;买&quot;</td><td>9.51</td><td>0.0</td><td>0.0</td><td>0.0</td><td>&quot;永东股份证券买入&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;000698&quot;</td><td>&quot;沈阳化工&quot;</td><td>2023-10-09</td><td>09:45:18</td><td>23800.0</td><td>4.053</td><td>96460.0</td><td>96402.56</td><td>&quot;卖&quot;</td><td>9.2</td><td>48.24</td><td>0.0</td><td>0.0</td><td>&quot;沈阳化工证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr><tr><td>&quot;605288&quot;</td><td>&quot;凯迪股份&quot;</td><td>2023-10-09</td><td>09:44:40</td><td>2500.0</td><td>40.838</td><td>102094.0</td><td>102032.21</td><td>&quot;卖&quot;</td><td>9.74</td><td>51.05</td><td>1.0</td><td>0.0</td><td>&quot;凯迪股份证券卖出&quot;</td><td>&quot;海通两融&quot;</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (53, 15)\n",
       "┌──────────┬──────────┬────────────┬──────────┬───┬────────┬────────┬──────────────────┬──────────┐\n",
       "│ 证券代码 ┆ 证券名称 ┆ 成交日期   ┆ 成交时间 ┆ … ┆ 过户费 ┆ 其他费 ┆ 备注             ┆ 券商     │\n",
       "│ ---      ┆ ---      ┆ ---        ┆ ---      ┆   ┆ ---    ┆ ---    ┆ ---              ┆ ---      │\n",
       "│ str      ┆ str      ┆ date       ┆ time     ┆   ┆ f64    ┆ f64    ┆ str              ┆ str      │\n",
       "╞══════════╪══════════╪════════════╪══════════╪═══╪════════╪════════╪══════════════════╪══════════╡\n",
       "│ 600638   ┆ 新黄浦   ┆ 2023-07-26 ┆ 09:33:56 ┆ … ┆ 0.61   ┆ 0.0    ┆ 新黄浦证券卖出   ┆ 海通两融 │\n",
       "│ 002492   ┆ 恒基达鑫 ┆ 2023-07-27 ┆ 09:30:42 ┆ … ┆ 0.0    ┆ 0.0    ┆ 恒基达鑫证券卖出 ┆ 海通两融 │\n",
       "│ 002136   ┆ 安 纳 达 ┆ 2023-07-27 ┆ 09:32:52 ┆ … ┆ 0.0    ┆ 0.0    ┆ 安 纳 达证券卖出 ┆ 海通两融 │\n",
       "│ 603967   ┆ 中创物流 ┆ 2023-08-22 ┆ 09:36:13 ┆ … ┆ 1.0    ┆ 0.0    ┆ 中创物流证券卖出 ┆ 海通两融 │\n",
       "│ 603967   ┆ 中创物流 ┆ 2023-08-04 ┆ 10:07:37 ┆ … ┆ 1.01   ┆ 0.0    ┆ 中创物流证券买入 ┆ 海通两融 │\n",
       "│ …        ┆ …        ┆ …          ┆ …        ┆ … ┆ …      ┆ …      ┆ …                ┆ …        │\n",
       "│ 300464   ┆ 星徽股份 ┆ 2023-10-18 ┆ 09:46:15 ┆ … ┆ 0.0    ┆ 0.0    ┆ 星徽股份证券卖出 ┆ 海通两融 │\n",
       "│ 002661   ┆ 克明食品 ┆ 2023-10-18 ┆ 09:55:41 ┆ … ┆ 0.0    ┆ 0.0    ┆ 克明食品证券买入 ┆ 海通两融 │\n",
       "│ 002753   ┆ 永东股份 ┆ 2023-10-09 ┆ 09:48:02 ┆ … ┆ 0.0    ┆ 0.0    ┆ 永东股份证券买入 ┆ 海通两融 │\n",
       "│ 000698   ┆ 沈阳化工 ┆ 2023-10-09 ┆ 09:45:18 ┆ … ┆ 0.0    ┆ 0.0    ┆ 沈阳化工证券卖出 ┆ 海通两融 │\n",
       "│ 605288   ┆ 凯迪股份 ┆ 2023-10-09 ┆ 09:44:40 ┆ … ┆ 1.0    ┆ 0.0    ┆ 凯迪股份证券卖出 ┆ 海通两融 │\n",
       "└──────────┴──────────┴────────────┴──────────┴───┴────────┴────────┴──────────────────┴──────────┘"
      ]
     },
     "execution_count": 277,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 278,
   "id": "e7859727-2bb8-46b4-a18a-1231219540aa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (53, 14)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>券商</th><th>交易日期</th><th>交易时间</th><th>证券代码</th><th>证券名称</th><th>买卖标志</th><th>成交价格</th><th>成交数量</th><th>成交金额</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>发生金额</th></tr><tr><td>str</td><td>date</td><td>time</td><td>str</td><td>str</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;海通两融&quot;</td><td>2023-07-26</td><td>09:33:56</td><td>&quot;600638&quot;</td><td>&quot;新黄浦&quot;</td><td>&quot;卖出&quot;</td><td>6.526</td><td>9300.0</td><td>60696.0</td><td>6.68</td><td>60.7</td><td>0.61</td><td>0.0</td><td>60628.01</td></tr><tr><td>&quot;海通两融&quot;</td><td>2023-07-27</td><td>09:30:42</td><td>&quot;002492&quot;</td><td>&quot;恒基达鑫&quot;</td><td>&quot;卖出&quot;</td><td>6.12</td><td>8700.0</td><td>53244.0</td><td>5.86</td><td>53.23</td><td>0.0</td><td>0.0</td><td>53184.91</td></tr><tr><td>&quot;海通两融&quot;</td><td>2023-07-27</td><td>09:32:52</td><td>&quot;002136&quot;</td><td>&quot;安 纳 达&quot;</td><td>&quot;卖出&quot;</td><td>11.881</td><td>4400.0</td><td>52277.0</td><td>5.75</td><td>52.28</td><td>0.0</td><td>0.0</td><td>52218.97</td></tr><tr><td>&quot;海通两融&quot;</td><td>2023-08-22</td><td>09:36:13</td><td>&quot;603967&quot;</td><td>&quot;中创物流&quot;</td><td>&quot;卖出&quot;</td><td>9.36</td><td>10600.0</td><td>99216.0</td><td>10.91</td><td>99.24</td><td>1.0</td><td>0.0</td><td>99104.85</td></tr><tr><td>&quot;海通两融&quot;</td><td>2023-08-04</td><td>10:07:37</td><td>&quot;603967&quot;</td><td>&quot;中创物流&quot;</td><td>&quot;买入&quot;</td><td>9.43</td><td>10600.0</td><td>99958.0</td><td>11.0</td><td>0.0</td><td>1.01</td><td>0.0</td><td>-99970.01</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;海通两融&quot;</td><td>2023-10-18</td><td>09:46:15</td><td>&quot;300464&quot;</td><td>&quot;星徽股份&quot;</td><td>&quot;卖出&quot;</td><td>5.74</td><td>16100.0</td><td>92414.0</td><td>8.82</td><td>46.21</td><td>0.0</td><td>0.0</td><td>92358.97</td></tr><tr><td>&quot;海通两融&quot;</td><td>2023-10-18</td><td>09:55:41</td><td>&quot;002661&quot;</td><td>&quot;克明食品&quot;</td><td>&quot;买入&quot;</td><td>9.42</td><td>8500.0</td><td>80072.0</td><td>7.64</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-80079.64</td></tr><tr><td>&quot;海通两融&quot;</td><td>2023-10-09</td><td>09:48:02</td><td>&quot;002753&quot;</td><td>&quot;永东股份&quot;</td><td>&quot;买入&quot;</td><td>7.02</td><td>14200.0</td><td>99684.0</td><td>9.51</td><td>0.0</td><td>0.0</td><td>0.0</td><td>-99693.51</td></tr><tr><td>&quot;海通两融&quot;</td><td>2023-10-09</td><td>09:45:18</td><td>&quot;000698&quot;</td><td>&quot;沈阳化工&quot;</td><td>&quot;卖出&quot;</td><td>4.053</td><td>23800.0</td><td>96460.0</td><td>9.2</td><td>48.24</td><td>0.0</td><td>0.0</td><td>96402.56</td></tr><tr><td>&quot;海通两融&quot;</td><td>2023-10-09</td><td>09:44:40</td><td>&quot;605288&quot;</td><td>&quot;凯迪股份&quot;</td><td>&quot;卖出&quot;</td><td>40.838</td><td>2500.0</td><td>102094.0</td><td>9.74</td><td>51.05</td><td>1.0</td><td>0.0</td><td>102032.21</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (53, 14)\n",
       "┌──────────┬────────────┬──────────┬──────────┬───┬────────┬────────┬────────┬───────────┐\n",
       "│ 券商     ┆ 交易日期   ┆ 交易时间 ┆ 证券代码 ┆ … ┆ 印花税 ┆ 过户费 ┆ 其他费 ┆ 发生金额  │\n",
       "│ ---      ┆ ---        ┆ ---      ┆ ---      ┆   ┆ ---    ┆ ---    ┆ ---    ┆ ---       │\n",
       "│ str      ┆ date       ┆ time     ┆ str      ┆   ┆ f64    ┆ f64    ┆ f64    ┆ f64       │\n",
       "╞══════════╪════════════╪══════════╪══════════╪═══╪════════╪════════╪════════╪═══════════╡\n",
       "│ 海通两融 ┆ 2023-07-26 ┆ 09:33:56 ┆ 600638   ┆ … ┆ 60.7   ┆ 0.61   ┆ 0.0    ┆ 60628.01  │\n",
       "│ 海通两融 ┆ 2023-07-27 ┆ 09:30:42 ┆ 002492   ┆ … ┆ 53.23  ┆ 0.0    ┆ 0.0    ┆ 53184.91  │\n",
       "│ 海通两融 ┆ 2023-07-27 ┆ 09:32:52 ┆ 002136   ┆ … ┆ 52.28  ┆ 0.0    ┆ 0.0    ┆ 52218.97  │\n",
       "│ 海通两融 ┆ 2023-08-22 ┆ 09:36:13 ┆ 603967   ┆ … ┆ 99.24  ┆ 1.0    ┆ 0.0    ┆ 99104.85  │\n",
       "│ 海通两融 ┆ 2023-08-04 ┆ 10:07:37 ┆ 603967   ┆ … ┆ 0.0    ┆ 1.01   ┆ 0.0    ┆ -99970.01 │\n",
       "│ …        ┆ …          ┆ …        ┆ …        ┆ … ┆ …      ┆ …      ┆ …      ┆ …         │\n",
       "│ 海通两融 ┆ 2023-10-18 ┆ 09:46:15 ┆ 300464   ┆ … ┆ 46.21  ┆ 0.0    ┆ 0.0    ┆ 92358.97  │\n",
       "│ 海通两融 ┆ 2023-10-18 ┆ 09:55:41 ┆ 002661   ┆ … ┆ 0.0    ┆ 0.0    ┆ 0.0    ┆ -80079.64 │\n",
       "│ 海通两融 ┆ 2023-10-09 ┆ 09:48:02 ┆ 002753   ┆ … ┆ 0.0    ┆ 0.0    ┆ 0.0    ┆ -99693.51 │\n",
       "│ 海通两融 ┆ 2023-10-09 ┆ 09:45:18 ┆ 000698   ┆ … ┆ 48.24  ┆ 0.0    ┆ 0.0    ┆ 96402.56  │\n",
       "│ 海通两融 ┆ 2023-10-09 ┆ 09:44:40 ┆ 605288   ┆ … ┆ 51.05  ┆ 1.0    ┆ 0.0    ┆ 102032.21 │\n",
       "└──────────┴────────────┴──────────┴──────────┴───┴────────┴────────┴────────┴───────────┘"
      ]
     },
     "execution_count": 278,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d3=d3.select(\n",
    "    券商=pl.col(\"券商\"),\n",
    "    交易日期=pl.col(\"成交日期\"),\n",
    "    交易时间=pl.col(\"成交时间\"),\n",
    "    证券代码=pl.col(\"证券代码\"),\n",
    "    证券名称=pl.col(\"证券名称\"),\n",
    "    买卖标志=pl.col(\"操作\").replace({\"卖\":\"卖出\",\"买\":\"买入\"}),\n",
    "    成交价格=pl.col(\"成交价格\"),\n",
    "    成交数量=pl.col(\"成交数量\").abs(),\n",
    "    成交金额=pl.col(\"成交金额\"),\n",
    "    手续费=pl.col(\"手续费\"),\n",
    "    印花税=pl.col(\"印花税\"),\n",
    "    过户费=pl.col(\"过户费\"),\n",
    "    其他费=pl.col(\"其他费\"),\n",
    "    发生金额=pl.col(\"发生金额\"),\n",
    ")\n",
    "d3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 279,
   "id": "642cafa2-a1f7-4a78-9c25-a2a5160edcf4",
   "metadata": {},
   "outputs": [],
   "source": [
    "df=pl.concat([d1,d2,d3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 280,
   "id": "74d5d64f-470c-41e0-b505-0b843c554c89",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><style>\n",
       ".dataframe > thead > tr,\n",
       ".dataframe > tbody > tr {\n",
       "  text-align: right;\n",
       "  white-space: pre-wrap;\n",
       "}\n",
       "</style>\n",
       "<small>shape: (363, 17)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>券商</th><th>交易日期</th><th>交易时间</th><th>证券代码</th><th>证券名称</th><th>买卖标志</th><th>成交价格</th><th>成交数量</th><th>成交金额</th><th>手续费</th><th>印花税</th><th>过户费</th><th>其他费</th><th>发生金额</th><th>成交金额2</th><th>成交金额D</th><th>发生金额D</th></tr><tr><td>str</td><td>date</td><td>time</td><td>str</td><td>str</td><td>str</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td><td>f64</td></tr></thead><tbody><tr><td>&quot;湘财&quot;</td><td>2022-07-18</td><td>09:44:52</td><td>&quot;600408&quot;</td><td>&quot;安泰集团&quot;</td><td>&quot;买入&quot;</td><td>3.19</td><td>47000.0</td><td>149930.0</td><td>23.99</td><td>0.0</td><td>1.51</td><td>0.0</td><td>-149955.5</td><td>149930.0</td><td>0.0</td><td>0.0</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-07-18</td><td>09:44:31</td><td>&quot;600648&quot;</td><td>&quot;外高桥&quot;</td><td>&quot;买入&quot;</td><td>12.6066</td><td>11900.0</td><td>150019.0</td><td>24.0</td><td>0.0</td><td>1.49</td><td>0.0</td><td>-150044.49</td><td>150018.54</td><td>0.46</td><td>0.0</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-07-18</td><td>09:43:38</td><td>&quot;600269&quot;</td><td>&quot;赣粤高速&quot;</td><td>&quot;买入&quot;</td><td>3.69</td><td>40700.0</td><td>150183.0</td><td>24.03</td><td>0.0</td><td>1.5</td><td>0.0</td><td>-150208.53</td><td>150183.0</td><td>0.0</td><td>0.0</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-07-18</td><td>09:42:51</td><td>&quot;600015&quot;</td><td>&quot;华夏银行&quot;</td><td>&quot;买入&quot;</td><td>5.07</td><td>30000.0</td><td>152100.0</td><td>24.34</td><td>0.0</td><td>1.52</td><td>0.0</td><td>-152125.86</td><td>152100.0</td><td>0.0</td><td>0.0</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-07-18</td><td>09:39:28</td><td>&quot;601992&quot;</td><td>&quot;金隅集团&quot;</td><td>&quot;卖出&quot;</td><td>2.5683</td><td>54000.0</td><td>138686.0</td><td>22.19</td><td>138.69</td><td>1.38</td><td>0.0</td><td>138523.74</td><td>138688.2</td><td>-2.2</td><td>0.0</td></tr><tr><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td><td>&hellip;</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-10-24</td><td>09:37:27</td><td>&quot;300283&quot;</td><td>&quot;温州宏丰&quot;</td><td>&quot;买入&quot;</td><td>5.4038</td><td>12900.0</td><td>69709.0</td><td>11.15</td><td>0.0</td><td>0.83</td><td>0.0</td><td>-69720.15</td><td>69709.02</td><td>-0.02</td><td>0.83</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-10-11</td><td>09:32:03</td><td>&quot;000900&quot;</td><td>&quot;现代投资&quot;</td><td>&quot;卖出&quot;</td><td>3.8465</td><td>34400.0</td><td>132321.0</td><td>21.17</td><td>132.35</td><td>1.31</td><td>0.0</td><td>132167.48</td><td>132319.6</td><td>1.4</td><td>1.31</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-07-18</td><td>09:38:10</td><td>&quot;002462&quot;</td><td>&quot;嘉事堂&quot;</td><td>&quot;卖出&quot;</td><td>13.2062</td><td>10400.0</td><td>137344.0</td><td>21.98</td><td>137.35</td><td>1.38</td><td>0.0</td><td>137184.67</td><td>137344.48</td><td>-0.48</td><td>1.38</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>09:33:37</td><td>&quot;000900&quot;</td><td>&quot;现代投资&quot;</td><td>&quot;买入&quot;</td><td>4.05</td><td>34400.0</td><td>139320.0</td><td>22.29</td><td>0.0</td><td>1.39</td><td>0.0</td><td>-139342.29</td><td>139320.0</td><td>0.0</td><td>1.39</td></tr><tr><td>&quot;湘财&quot;</td><td>2022-07-11</td><td>09:38:16</td><td>&quot;002462&quot;</td><td>&quot;嘉事堂&quot;</td><td>&quot;买入&quot;</td><td>13.51</td><td>10400.0</td><td>140504.0</td><td>22.48</td><td>0.0</td><td>1.41</td><td>0.0</td><td>-140526.48</td><td>140504.0</td><td>0.0</td><td>1.41</td></tr></tbody></table></div>"
      ],
      "text/plain": [
       "shape: (363, 17)\n",
       "┌──────┬────────────┬──────────┬──────────┬───┬────────────┬───────────┬───────────┬───────────┐\n",
       "│ 券商 ┆ 交易日期   ┆ 交易时间 ┆ 证券代码 ┆ … ┆ 发生金额   ┆ 成交金额2 ┆ 成交金额D ┆ 发生金额D │\n",
       "│ ---  ┆ ---        ┆ ---      ┆ ---      ┆   ┆ ---        ┆ ---       ┆ ---       ┆ ---       │\n",
       "│ str  ┆ date       ┆ time     ┆ str      ┆   ┆ f64        ┆ f64       ┆ f64       ┆ f64       │\n",
       "╞══════╪════════════╪══════════╪══════════╪═══╪════════════╪═══════════╪═══════════╪═══════════╡\n",
       "│ 湘财 ┆ 2022-07-18 ┆ 09:44:52 ┆ 600408   ┆ … ┆ -149955.5  ┆ 149930.0  ┆ 0.0       ┆ 0.0       │\n",
       "│ 湘财 ┆ 2022-07-18 ┆ 09:44:31 ┆ 600648   ┆ … ┆ -150044.49 ┆ 150018.54 ┆ 0.46      ┆ 0.0       │\n",
       "│ 湘财 ┆ 2022-07-18 ┆ 09:43:38 ┆ 600269   ┆ … ┆ -150208.53 ┆ 150183.0  ┆ 0.0       ┆ 0.0       │\n",
       "│ 湘财 ┆ 2022-07-18 ┆ 09:42:51 ┆ 600015   ┆ … ┆ -152125.86 ┆ 152100.0  ┆ 0.0       ┆ 0.0       │\n",
       "│ 湘财 ┆ 2022-07-18 ┆ 09:39:28 ┆ 601992   ┆ … ┆ 138523.74  ┆ 138688.2  ┆ -2.2      ┆ 0.0       │\n",
       "│ …    ┆ …          ┆ …        ┆ …        ┆ … ┆ …          ┆ …         ┆ …         ┆ …         │\n",
       "│ 湘财 ┆ 2022-10-24 ┆ 09:37:27 ┆ 300283   ┆ … ┆ -69720.15  ┆ 69709.02  ┆ -0.02     ┆ 0.83      │\n",
       "│ 湘财 ┆ 2022-10-11 ┆ 09:32:03 ┆ 000900   ┆ … ┆ 132167.48  ┆ 132319.6  ┆ 1.4       ┆ 1.31      │\n",
       "│ 湘财 ┆ 2022-07-18 ┆ 09:38:10 ┆ 002462   ┆ … ┆ 137184.67  ┆ 137344.48 ┆ -0.48     ┆ 1.38      │\n",
       "│ 湘财 ┆ 2022-07-11 ┆ 09:33:37 ┆ 000900   ┆ … ┆ -139342.29 ┆ 139320.0  ┆ 0.0       ┆ 1.39      │\n",
       "│ 湘财 ┆ 2022-07-11 ┆ 09:38:16 ┆ 002462   ┆ … ┆ -140526.48 ┆ 140504.0  ┆ 0.0       ┆ 1.41      │\n",
       "└──────┴────────────┴──────────┴──────────┴───┴────────────┴───────────┴───────────┴───────────┘"
      ]
     },
     "execution_count": 280,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.with_columns(\n",
    "    成交金额2=pl.col(\"成交价格\")*pl.col(\"成交数量\"),\n",
    ").with_columns(\n",
    "    成交金额D=pl.col(\"成交金额\")-pl.col(\"成交金额2\"),\n",
    ").with_columns(\n",
    "    发生金额D=(\n",
    "        pl.col(\"发生金额\")\n",
    "        -(\n",
    "            pl.when(pl.col(\"买卖标志\")==\"买入\")\n",
    "            .then(-pl.col(\"成交金额\"))\n",
    "            .when((pl.col(\"买卖标志\")==\"卖出\"))\n",
    "            .then(pl.col(\"成交金额\"))\n",
    "            -pl.col(\"手续费\")\n",
    "            -pl.col(\"印花税\")\n",
    "            -pl.col(\"过户费\")\n",
    "            -pl.col(\"其他费\")\n",
    "        )\n",
    "    ).round(4)\n",
    ").sort(\"发生金额D\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 281,
   "id": "48904d83-c14c-4d0e-b456-c3d6cc360e8d",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.write_parquet(\"stock_trades.parquet\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 282,
   "id": "2775975a-9537-4b64-ba87-4ade3dea6c50",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.write_csv(\"stock_trades.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 283,
   "id": "e2d21866-dd01-4e9f-9ebd-7cc53df3d74e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<xlsxwriter.workbook.Workbook at 0x244e0541e20>"
      ]
     },
     "execution_count": 283,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.write_excel(\"stock_trades.xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ecb252c1-3f95-49dd-b2be-31dec479ee75",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ff680f58-2b12-40fa-8a7c-d24efec38d0f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
